﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using WPFExcelReport.Helpers;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class TGBVK 
    {
        #region ==dwKEY===========
        public static readonly DependencyProperty dwKEYProperty = DependencyProperty.Register("dwKEY",
            typeof(DataRow), typeof(TGBVK),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwKEYChanged));
        public DataRow dwKEY
        {
            get
            {
                return (DataRow)GetValue(dwKEYProperty);
            }
            set
            {
                SetValue(dwKEYProperty, value);
                MV.SetProd.Clear();
            }
        }
        private static void OndwKEYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TGBVK;
            if (src != null)
            {
                src.dwKEY = (DataRow)e.NewValue; 
            }
        }
        #endregion
        BindingListCollectionView cvMaster
        {
            get
            {
                return (BindingListCollectionView)CollectionViewSource.GetDefaultView(this.dlgMaster.ItemsSource);
            }
        }

        public TGBVK()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_STOCK();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            base.Window_Loaded(sender, e);
        }
        DataRow LastdwKEY = null; 

        private void Load_Click(object sender, RoutedEventArgs e)
        {
            if (LastdwKEY == dwKEY)
                return;
            LastdwKEY = dwKEY;
            if (dwKEY == null)
                return;
            string ART, VAR, FARBE, SPPART, LO, LB, MDATE;
            DataTable tb;
            ART = dwKEY["ART"].ToString();
            VAR = dwKEY["VAR"].ToString();
            FARBE = dwKEY["FARBE"].ToString();
            LO = dwKEY["LO"].ToString();
            LB = dwKEY["LB"].ToString();
            SPPART = dwKEY["SPPART"].ToString();
            MDATE = dwKEY["MDATE"].ToString();
            ((VICC_STOCK)MV).RefreshStock(MDATE, 1);
            DataSet SResult = ((VICC_STOCK)MV).LoadStock(MDATE, LO, LB, ART, VAR, SPPART);
            MergeData(SResult, true);
        }
    }
}
